package com.ss.android.article.base.feature.detail2.article.a;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.RoundingParams;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.base.feature.app.d.CommonImpressionAdapter;
import com.ss.android.article.base.feature.app.schema.AdsAppActivity;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.model.MixedAdsData;
import com.ss.android.article.base.feature.detail.model.PhoneAdsData;
import com.ss.android.article.base.feature.detail.model.WebInfo;
import com.ss.android.article.base.feature.detail2.a.a.AppAdViewHolder;
import com.ss.android.article.base.feature.detail2.a.c.DetailAdLargePicLayout;
import com.ss.android.article.base.feature.detail2.a.c.DetailAdMediaLayout;
import com.ss.android.article.base.feature.detail2.a.c.DetailAdSmallPicLayout;
import com.ss.android.article.base.feature.detail2.a.c.DetailAdVideoLayout;
import com.ss.android.article.base.feature.detail2.widget.LikeAndRewardsLayout;
import com.ss.android.article.base.feature.detail2.widget.RelatedNewsHolder;
import com.ss.android.article.base.feature.detail2.widget.a.DetailAdAppLayout;
import com.ss.android.article.base.feature.detail2.widget.a.DetailAdBannerLayout;
import com.ss.android.article.base.feature.detail2.widget.a.DetailAdImageLayout;
import com.ss.android.article.base.feature.detail2.widget.a.DetailAdMixBannerLayout;
import com.ss.android.article.base.feature.detail2.widget.a.DetailAdTextLinkLayout;
import com.ss.android.article.base.feature.detail2.widget.RelatedNewsLayout;
import com.ss.android.article.base.feature.detail2.widget.tagview.TagLayout;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.DownloadAppAd;
import com.ss.android.article.base.feature.update.a.UserInfo;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.b.a.AdsAppItem;
import com.ss.android.b.a.BaseAdsData;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.app.LifeCycleInvoker;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

import im.quar.autolayout.utils.AutoUtils;

public final class NewDetailPageExtra {
    private CommonImpressionAdapter mCommentImpressionAdapter;
    private int B;
    final Activity mActivity;
    public TagLayout mTagLayout;
    public LikeAndRewardsLayout mLikeAndRewardsLayout;
    public RelatedNewsLayout d;
    public LinearLayout mDetailAdContainer;
    public View mSofaLayout;
    public TextView mSofaText;
    public View mContentsWrapper;
    public ArticleInfo mArticleInfo;
    public Article mArticle;
    long k;
    private final AppData mAppData;
    private LinearLayout mHeaderLayout;
    private TextView n;
    private DetailAdAppLayout mDetailAdAppLayout;
    private AppAdViewHolder mAppAdViewHolder;
    private DetailAdMixBannerLayout mDetailAdMixBannerLayout;
    private DetailAdImageLayout mDetailAdImageLayout;
    private DetailAdVideoLayout mDetailAdVideoLayout;
    private DetailAdSmallPicLayout mDetailAdSmallPicLayout;
    private DetailAdLargePicLayout mDetailAdLargePicLayout;
    private com.ss.android.article.base.feature.detail2.a.c.DetailAdGroupPicLayout mDetailAdGroupPicLayout;
    private DetailAdBannerLayout mDetailAdBannerLayout;
    private DetailAdTextLinkLayout mDetailAdTextLinkLayout;
    private DetailAdMediaLayout mDetailAdMediaLayout;
    private int[] z = new int[2];

    public NewDetailPageExtra(Activity activity, LinearLayout headerLayout, View view) {
        this.mActivity = activity;
        this.mAppData = AppData.getInstance();
        this.mHeaderLayout = headerLayout;
        this.mContentsWrapper = view.findViewById(com.ss.android.article.browser.R.id.contents_wrapper);
        this.mSofaLayout = view.findViewById(com.ss.android.article.browser.R.id.sofa_layout);
        this.mSofaText = this.mSofaLayout.findViewById(com.ss.android.article.browser.R.id.sofa_text);
    }

    public final void setContentsVisibility(int visibility) {
        this.mContentsWrapper.setVisibility(visibility);
    }

    public final void setArticle(Article article) {
        this.mArticle = article;
        if (this.mArticleInfo == null
                || article == null
                || this.mArticleInfo.itemId != article.groupId) {
            this.mSofaLayout.setVisibility(View.GONE);
        }
    }

    public final void setSofaLayoutVisibility(boolean visible) {
        int v0 = visible ? View.VISIBLE : View.GONE;
        this.mSofaLayout.setVisibility(v0);
    }

    public final void a(int[] arg10) {
        int v2;
        RelatedNewsLayout v4;
        int v3_1;
        int v0 = -1;
        int v1 = 0;
        if (this.mDetailAdVideoLayout != null && this.mDetailAdContainer != null) {
            int[] v3 = new int[2];
            this.mDetailAdVideoLayout.getLocationOnScreen(v3);
            v3_1 = v3[1];
            if (this.mDetailAdVideoLayout.getMeasuredHeight() + v3_1 < 0
                    || v3_1 > this.mActivity.getResources().getDisplayMetrics().heightPixels) {
                this.mDetailAdVideoLayout.releaseMedia();
            }
        }

        if (this.mCommentImpressionAdapter != null && arg10 != null) {
            RelatedNewsLayout v3_2 = null;
            switch (this.B) {
                case 9: {
                    v4 = this.d;
                    break;
                }
                default: {
                    v4 = v3_2;
                    break;
                }
            }

            if (v4 == null) {
                return;
            }

            v3_1 = v4.getChildCount();
            if (v3_1 <= 0) {
                return;
            }

            if (v4.getVisibility() != View.VISIBLE || arg10[1] <= arg10[0]) {
                label_92:
                v1 = v0;
            } else {
                View v5 = v4.getChildAt(0);
                View v4_1 = v4.getChildAt(v3_1 - 1);
                int v6 = v5.getHeight();
                if (v6 > 0) {
                    v5.getLocationInWindow(this.z);
                    int v5_1 = this.z[1];
                    v4_1.getLocationInWindow(this.z);
                    int v4_2 = this.z[1] + v6;
                    if (v5_1 > arg10[1]) {
                        v1 = v0;
                    } else if (v4_2 >= arg10[0]) {
                        v0 = v5_1 < arg10[0] ? (arg10[0] - v5_1) / v6 : 0;
                        if (v4_2 < arg10[1]) {
                            v1 = 1;
                            v2 = v3_1;
                        } else {
                            v4_2 = (arg10[1] - v5_1) / v6;
                            if ((arg10[1] - v5_1) % v6 == 0) {
                                v1 = 1;
                                v2 = v4_2;
                            } else {
                                v2 = v4_2;
                            }
                        }

                        int v8 = Math.min(v2 - v1, v3_1 - 1);
                        v1 = v0;
                        v0 = v8;
                    } else {
                        v1 = v0;
                    }
                } else {
                    return;
                }
            }

            this.mCommentImpressionAdapter.b(v1, v0);
        }
    }

    public final void initExtras(ArticleInfo articleInfo, long arg20, View.OnClickListener arg22, View.OnClickListener arg23) {
        int v5_2;
        int v14;
        if (articleInfo != null) {
            if (this.mArticleInfo != null || articleInfo == null) {
                if (this.mArticleInfo != null && articleInfo != null && this.mArticleInfo.itemId != articleInfo.itemId) {
                    v14 = 1;
                } else {
                    v14 = 0;
                }
            } else {
                v14 = 1;
            }

            this.mArticleInfo = articleInfo;
            this.k = arg20;
            this.mHeaderLayout.removeAllViews();
            if (!TextUtils.isEmpty(articleInfo.alertText)) {
                String v5 = articleInfo.alertText;
                if (!TextUtils.isEmpty(v5)) {
                    if (this.n == null) {
                        this.n = new TextView(this.mActivity);
                        this.n.setTextColor(this.mActivity.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi3));
                        int fontSizePref = this.mAppData.mFontSizePref;
                        if (fontSizePref < 0 || fontSizePref > 3) {
                            fontSizePref = 0;
                        }
                        this.n.setTextSize(((float) ArticleConstants.K[fontSizePref]));
                        this.n.setLineSpacing(this.n.getTextSize() * 1.5f, 0f);
                        this.n.setLayoutParams(NewDetailPageExtra.b(AutoUtils.scaleValue(60)));
                    }

                    this.mHeaderLayout.addView(this.n);
                    this.n.setText(((CharSequence) v5));
                }
            }

            Iterator v15 = articleInfo.X.entrySet().iterator();
            while (v15.hasNext()) {
                Object v4_1 = v15.next();
                String v5_1 = (String) ((Entry) v4_1).getKey();
                v4_1 = ((Entry) v4_1).getValue();
                int v6 = -1;
                switch (v5_1) {
                    case "labels": {
                        v5_2 = 0;
                        break;
                    }
                    case "admin_debug": {
                        v5_2 = 4;
                        break;
                    }
                    case "ad": {
                        v5_2 = 1;
                        break;
                    }
                    case "related_news": {
                        v5_2 = 3;
                        break;
                    }
                    case "like_and_rewards": {
                        v5_2 = 2;
                        break;
                    }
                    default: {
                        label_100:
                        v5_2 = v6;
                        break;
                    }
                }

                switch (v5_2) {
                    case 0: {
                        this.a(((List) v4_1));
                        continue;
                    }
                    case 1: {
                        if (v4_1 == null) {
                            continue;
                        }

                        if (this.mDetailAdContainer == null) {
                            this.mDetailAdContainer = new LinearLayout(this.mActivity);
                            this.mDetailAdContainer.setOrientation(LinearLayout.VERTICAL);
                            this.mDetailAdContainer.setLayoutParams(NewDetailPageExtra.b(AutoUtils.scaleValue(60)));
                        } else {
                            this.mDetailAdContainer.removeAllViews();
                        }

                        this.mHeaderLayout.addView(this.mDetailAdContainer);
                        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
                        layoutParams.bottomMargin = ((int) UIUtils.dp2px(this.mActivity, 8f));
                        DownloadAppAd downloadAppAd = ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).f;
                        if (downloadAppAd != null && (downloadAppAd.isValid())) {
                            if ((ToolUtils.isAppInstalled(this.mActivity, downloadAppAd.pkg)) && (downloadAppAd.a(this.mActivity))) {
                                JSONObject v12 = new JSONObject();
                                try {
                                    v12.put("log_extra", downloadAppAd.logExtra);
                                } catch (JSONException jsonException) {
                                    jsonException.printStackTrace();
                                }

                                MobAdClickCombiner.onAdEvent(this.mActivity, "detail_ad", "hide", downloadAppAd.id, 0, v12, 1);
                            } else {
                                if (downloadAppAd.displaySubtype == 0) {
                                    this.mDetailAdAppLayout = new DetailAdAppLayout(this.mActivity);
                                    this.mDetailAdAppLayout.setLayoutParams(layoutParams);
                                    this.mDetailAdContainer.addView(this.mDetailAdAppLayout);
                                    this.mAppAdViewHolder = new AppAdViewHolder(this.mActivity);
                                    this.mAppAdViewHolder.initView(this.mDetailAdAppLayout);
                                    this.mAppAdViewHolder.a(downloadAppAd);
                                } else if (downloadAppAd.displaySubtype == 1) {
                                    this.mDetailAdSmallPicLayout = new DetailAdSmallPicLayout(this.mActivity);
                                    this.mDetailAdSmallPicLayout.a(((BaseAdsData) downloadAppAd));
                                    this.mDetailAdSmallPicLayout.setLayoutParams(layoutParams);
                                    this.mDetailAdContainer.addView(this.mDetailAdSmallPicLayout);
                                } else if (downloadAppAd.displaySubtype == 2) {
                                    this.mDetailAdVideoLayout = new DetailAdVideoLayout(this.mActivity);
                                    this.mDetailAdVideoLayout.setArticle(this.mArticle);
                                    this.mDetailAdVideoLayout.setAdData(downloadAppAd);
                                    this.mDetailAdVideoLayout.setLayoutParams(layoutParams);
                                    this.mDetailAdContainer.addView(this.mDetailAdVideoLayout);
                                } else if (downloadAppAd.displaySubtype == 3) {
                                    this.mDetailAdLargePicLayout = new DetailAdLargePicLayout(this.mActivity);
                                    this.mDetailAdLargePicLayout.a(downloadAppAd);
                                    this.mDetailAdLargePicLayout.setLayoutParams(layoutParams);
                                    this.mDetailAdContainer.addView(this.mDetailAdLargePicLayout);
                                } else if (downloadAppAd.displaySubtype == 4) {
                                    this.mDetailAdGroupPicLayout = new com.ss.android.article.base.feature.detail2.a.c.DetailAdGroupPicLayout(this.mActivity);
                                    this.mDetailAdGroupPicLayout.setAdData(((BaseAdsData) downloadAppAd));
                                    this.mDetailAdGroupPicLayout.setLayoutParams(layoutParams);
                                    this.mDetailAdContainer.addView(this.mDetailAdGroupPicLayout);
                                } else {
                                    downloadAppAd.K = false;
                                }
                                AppUtil.a(downloadAppAd.trackUrlList, this.mActivity);
                            }
                        }
                        if (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a != null && (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a.isValid())) {
                            MixedAdsData v5_4 = ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a;
                            if (v5_4.g == 3) {
                                this.mDetailAdMixBannerLayout = new DetailAdMixBannerLayout(this.mActivity);
                                this.mDetailAdMixBannerLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdMixBannerLayout);
                                this.mDetailAdMixBannerLayout.a(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a);
                                this.mDetailAdMixBannerLayout.a(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a.d, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a.e, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a.f);
                                this.mDetailAdMixBannerLayout.setVisibility(View.VISIBLE);
                                this.mDetailAdMixBannerLayout.setOnClickListener(new View.OnClickListener() {

                                    public final void onClick(View arg4) {
                                        if(NewDetailPageExtra.this.mArticleInfo != null) {
                                            NewDetailPageExtra.this.a(NewDetailPageExtra.this.mActivity, NewDetailPageExtra.this.mArticleInfo.y);
                                        }
                                    }
                                });
                            } else if (v5_4.g == 1) {
                                this.mDetailAdSmallPicLayout = new DetailAdSmallPicLayout(this.mActivity);
                                this.mDetailAdSmallPicLayout.a(this.mArticleInfo.y);
                                this.mDetailAdSmallPicLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdSmallPicLayout);
                            } else if (v5_4.g == 2) {
                                this.mDetailAdVideoLayout = new DetailAdVideoLayout(this.mActivity);
                                this.mDetailAdVideoLayout.setArticle(this.mArticle);
                                this.mDetailAdVideoLayout.setAdData(this.mArticleInfo.y);
                                this.mDetailAdVideoLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdVideoLayout);
                            } else if (v5_4.g == 4) {
                                this.mDetailAdGroupPicLayout = new com.ss.android.article.base.feature.detail2.a.c.DetailAdGroupPicLayout(this.mActivity);
                                this.mDetailAdGroupPicLayout.setAdData(this.mArticleInfo.y);
                                this.mDetailAdGroupPicLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdGroupPicLayout);
                            } else {
                                ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).a.K = false;
                            }
                        }

                        if (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).b != null && (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).b.isValid())) {
                            PhoneAdsData v5_5 = ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).b;
                            if (v5_5.displaySubType == 1) {
                                this.mDetailAdSmallPicLayout = new DetailAdSmallPicLayout(this.mActivity);
                                this.mDetailAdSmallPicLayout.a(this.mArticleInfo.z);
                                this.mDetailAdSmallPicLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdSmallPicLayout);
                            } else if (v5_5.displaySubType == 2) {
                                this.mDetailAdVideoLayout = new DetailAdVideoLayout(this.mActivity);
                                this.mDetailAdVideoLayout.setArticle(this.mArticle);
                                this.mDetailAdVideoLayout.setAdData(this.mArticleInfo.z);
                                this.mDetailAdVideoLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdVideoLayout);
                            } else if (v5_5.displaySubType == 3) {
                                this.mDetailAdLargePicLayout = new DetailAdLargePicLayout(this.mActivity);
                                this.mDetailAdLargePicLayout.a(this.mArticleInfo.z);
                                this.mDetailAdLargePicLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdLargePicLayout);
                            } else if (v5_5.displaySubType == 4) {
                                this.mDetailAdGroupPicLayout = new com.ss.android.article.base.feature.detail2.a.c.DetailAdGroupPicLayout(this.mActivity);
                                this.mDetailAdGroupPicLayout.setAdData(this.mArticleInfo.z);
                                this.mDetailAdGroupPicLayout.setLayoutParams(layoutParams);
                                this.mDetailAdContainer.addView(this.mDetailAdGroupPicLayout);
                            } else {
                                ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).b.K = false;
                            }
                        }

                        if (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).d != null && (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).d.isValid())) {
                            this.mDetailAdImageLayout = new DetailAdImageLayout(this.mActivity);
                            this.mDetailAdImageLayout.setLayoutParams(layoutParams);
                            this.mDetailAdContainer.addView(this.mDetailAdImageLayout);
                            this.mDetailAdImageLayout.setImageUrl(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).d.image, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).d.imageWidth, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).d.imageHeight);
                            this.mDetailAdImageLayout.setText(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).d.label);
                            this.mDetailAdImageLayout.setVisibility(View.VISIBLE);
                            this.mDetailAdImageLayout.setOnClickListener(new com.ss.android.article.base.feature.detail2.article.a.d(this));
                        }

                        if (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData != null && (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.isValid())) {
                            this.mDetailAdBannerLayout = new DetailAdBannerLayout(this.mActivity);
                            this.mDetailAdBannerLayout.setLayoutParams(layoutParams);
                            this.mDetailAdContainer.addView(this.mDetailAdBannerLayout);
                            this.mDetailAdBannerLayout.a(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.image, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.imageWidth, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.imageHeight);
                            this.mDetailAdBannerLayout.setTitleText(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.title);
                            this.mDetailAdBannerLayout.setDescText(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.description);
                            this.mDetailAdBannerLayout.setLabelText(((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).mBannerAdsData.label);
                            this.mDetailAdBannerLayout.setVisibility(View.VISIBLE);
                            this.mDetailAdBannerLayout.setOnClickListener(new com.ss.android.article.base.feature.detail2.article.a.e(this));
                        }

                        if (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).g != null && (((com.ss.android.article.base.feature.detail.model.ArticleInfo.a) v4_1).g.isValid())) {
                            this.mDetailAdMediaLayout = new DetailAdMediaLayout(this.mActivity);
                            this.mDetailAdMediaLayout.setLayoutParams(layoutParams);
                            final DetailAdMediaLayout v5_6 = this.mDetailAdMediaLayout;
                            final ArticleInfo v6_1 = this.mArticleInfo;
                            v5_6.adMediaPicIv.setUrl(v6_1.E.d);
                            v5_6.adMediaPicIv.setAspectRatio((((float) v6_1.E.g)) / (((float) v6_1.E.h)));
                            v5_6.adMediaTitleTv.setText(v6_1.E.title);
                            v5_6.adMediaContentTv.setText(v6_1.E.e);
                            try {
                                v5_6.jsonObject = new JSONObject();
                                v5_6.jsonObject.put("log_extra", v6_1.E.logExtra);
                                v5_6.jsonObject.put("item_id", v6_1.groupItemId);
                                if (v6_1.mMediaInfo != null) {
                                    v5_6.jsonObject.put("media_id", v6_1.mMediaInfo.id);
                                }
                            } catch (JSONException v4_2) {
                                v4_2.printStackTrace();
                            }
                            v5_6.setOnClickListener(new View.OnClickListener() {

                                public final void onClick(View view) {
                                    String v0 = AppLog.a(AdsAppActivity.b(v6_1.E.f), false);
                                    if (!android.support.design.a.isTextEmpty(v0)) {
                                        MobClickCombiner.onEvent(v5_6.getContext(),
                                                "detail_ad",
                                                "click", v6_1.E.id, 0, v5_6.jsonObject);
                                        AppUtil.b(v5_6.getContext(), v0);
                                    }
                                }
                            });
                            this.mDetailAdMediaLayout.setVisibility(View.VISIBLE);
                            this.mDetailAdContainer.addView(this.mDetailAdMediaLayout);
                        }

                        if (this.mDetailAdContainer == null) {
                            continue;
                        }

                        if (this.mDetailAdContainer.getChildCount() <= 0) {
                            continue;
                        }

                        this.mDetailAdContainer.getChildAt(this.mDetailAdContainer.getChildCount() - 1).setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
                        continue;
                    }
                    case 2: {
                        if (this.mLikeAndRewardsLayout == null) {
                            this.mLikeAndRewardsLayout = new LikeAndRewardsLayout(this.mActivity);
                            this.mLikeAndRewardsLayout.setLayoutParams(NewDetailPageExtra.b(AutoUtils.scaleValue(60)));
                        }

                        this.mHeaderLayout.addView(this.mLikeAndRewardsLayout);
                        this.mLikeAndRewardsLayout.setAdmireButtonVisible(false);
                        this.mLikeAndRewardsLayout.setAdmireNum(0);
                        this.mLikeAndRewardsLayout.setRewardUserAvatars(Collections.emptyList());
                        this.mLikeAndRewardsLayout.setOnLikeClickListener(arg22);
                        this.mLikeAndRewardsLayout.setOnReportClickListener(arg23);
                        this.mLikeAndRewardsLayout.setLiked(((com.ss.android.article.base.feature.detail.model.ArticleInfo.b) v4_1).userLike);
                        this.mLikeAndRewardsLayout.setLikeNum(((com.ss.android.article.base.feature.detail.model.ArticleInfo.b) v4_1).likeNum);
                        continue;
                    }
                    case 3: {
                        if (((List) v4_1).isEmpty()) {
                            continue;
                        }
                        if (v14 != 0) {
                            v6 = ((List) v4_1).size();
                            if (v6 > 0 && this.mArticleInfo != null) {
                                if (this.mCommentImpressionAdapter != null) {
                                    this.mCommentImpressionAdapter.f();
                                    if ((this.mActivity instanceof LifeCycleInvoker)) {
                                        ((LifeCycleInvoker) this.mActivity).unregisterLifeCycleMonitor(this.mCommentImpressionAdapter);
                                    }
                                }

                                this.mCommentImpressionAdapter = new com.ss.android.article.base.feature.detail2.article.a.g(this, android.support.design.a.a(this.mArticleInfo.itemId, this.mArticleInfo.groupItemId, null));
                                if ((this.mActivity instanceof LifeCycleInvoker)) {
                                    ((LifeCycleInvoker) this.mActivity).registerLifeCycleMonitor(this.mCommentImpressionAdapter);
                                }

                                this.mCommentImpressionAdapter.a(v6, 37);
                                this.B = 9;
                            }
                        }

                        if (this.d == null) {
                            this.d = new RelatedNewsLayout(this.mActivity);
                            this.d.setLayoutParams(NewDetailPageExtra.b(AutoUtils.scaleValue(60)));
                        } else {
                            this.d.removeAllViews();
                        }

                        this.mHeaderLayout.addView(this.d);
                        RelatedNewsLayout v5_7 = this.d;
                        long v6_2 = this.mArticle != null ? this.mArticle.groupId : 0;
                        v5_7.addRelatedNewsItems(((List) v4_1), v6_2);
                        continue;
                    }
                    case 4: {
                        if (v4_1 == null) {
                            continue;
                        }

                        this.mDetailAdTextLinkLayout = new DetailAdTextLinkLayout(this.mActivity);
                        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
                        layoutParams.bottomMargin = ((int) UIUtils.dp2px(this.mActivity, 8f));
                        layoutParams.topMargin = ((int) UIUtils.dp2px(this.mActivity, 8f));
                        this.mDetailAdTextLinkLayout.setLayoutParams(layoutParams);
                        this.mHeaderLayout.addView(this.mDetailAdTextLinkLayout);
                        this.mDetailAdTextLinkLayout.setTitleText(((WebInfo) v4_1).title);
                        this.mDetailAdTextLinkLayout.setVisibility(View.VISIBLE);

                        this.mDetailAdTextLinkLayout.setTitleOnClickListener(new com.ss.android.article.base.feature.detail2.article.a.h(this, (WebInfo) v4_1));
                        continue;
                    }
                }
                continue;
            }

            if (this.mHeaderLayout.getChildCount() <= 0) {
                return;
            }

            this.mHeaderLayout.getChildAt(0).setLayoutParams(NewDetailPageExtra.b(AutoUtils.scaleValue(44)));
        }
    }

    public final void a(UserInfo arg7) {
        int v0 = 1;
        if (this.mLikeAndRewardsLayout != null) {
            int v2 = this.mLikeAndRewardsLayout.a.getVisibility() == View.VISIBLE ? 1 : 0;
            if (v2 == 0) {
                return;
            }

            v2 = this.mLikeAndRewardsLayout.getAdmireNum() + 1;
            int v3 = this.mLikeAndRewardsLayout.getAvatarCount() + 1;
            if (this.mActivity.getResources().getDisplayMetrics().densityDpi >= 320) {
                v0 = 0;
            }

            if (v2 > 999) {
                v0 = v0 != 0 ? 6 : 8;
            } else if (v0 != 0) {
                v0 = 7;
            } else {
                v0 = 9;
            }

            this.mLikeAndRewardsLayout.setAdmireNum(v2);
            if (v3 >= v0) {
                return;
            }

            LikeAndRewardsLayout v0_1 = this.mLikeAndRewardsLayout;
            ++v0_1.h;
            v0_1.f.addView(v0_1.a(arg7));
            if (v0_1.e.getVisibility() == View.VISIBLE) {
                return;
            }

            v0_1.e.setVisibility(View.VISIBLE);
        }
    }

    private void a(List arg11) {
        if (this.mTagLayout != null) {
            this.mTagLayout.removeAllViews();
        }

        if (arg11 != null && !arg11.isEmpty()) {
            int v4 = AutoUtils.scaleValue(12);
            if (this.mTagLayout == null) {
                this.mTagLayout = new TagLayout(this.mActivity);
                this.mTagLayout.setHorizontalSpacing(v4);
                this.mTagLayout.setVerticalSpacing(v4);
                this.mTagLayout.setLayoutParams(NewDetailPageExtra.b(AutoUtils.scaleValue(60)));
            }

            this.mHeaderLayout.addView(this.mTagLayout);
            int v5 = UIUtils.getScreenWidth(this.mActivity) - (this.mActivity.getResources().getDimensionPixelSize(R.dimen.d6) << 1);
            int v1 = 0;
            int v3 = 0;
            while (v1 < arg11.size()) {
                Object v0 = arg11.get(v1);
                int v6 = v1 + 1;
                TextView v7 = TagLayout.a(this.mActivity, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.d) v0).a);
                ((View) v7).measure(0, 0);
                v3 += ((View) v7).getMeasuredWidth();
                if (v1 > 0) {
                    v3 += v4;
                }

                if (v3 > v5) {
                    return;
                }

                this.mTagLayout.a(((View) v7), new com.ss.android.article.base.feature.detail2.article.a.f(this, v6, ((com.ss.android.article.base.feature.detail.model.ArticleInfo.d) v0)));
                ++v1;
            }
        }
    }

    public final void a() {
        ArticleInfo articleInfo = this.mArticleInfo;
        if (articleInfo != null && this.mLikeAndRewardsLayout != null) {
            this.mLikeAndRewardsLayout.mDiggLayout.onDiggClick();
            LikeAndRewardsLayout v1 = this.mLikeAndRewardsLayout;
            int likeNum = articleInfo.Y != null ? articleInfo.Y.likeNum : 0;
            v1.setLikeNum(likeNum);
        }
    }

    protected final void a(Context context, BaseAdsData arg19) {
        String v10 = "detail_ad";
        if (arg19 != null) {
            if (arg19.adType == 1) {
                AdsAppItem.a(context, arg19.openUrl, arg19.pkg, arg19.downloadUrl, arg19.webUrl, arg19.id, arg19.appName, v10, null, "download_confirm", arg19.appName, "", arg19.alertText, arg19.logExtra);
            } else if (arg19.adType == 2) {
                AdsAppItem.a(context, arg19.openUrl, arg19.webUrl, arg19.webTitle, arg19.orientation, new AdsAppItem.b(this.mActivity, v10, "click", arg19.id, arg19.logExtra));
            }
        }
    }

    public final boolean b() {
        boolean v0 = false;
        if (this.mArticleInfo != null && this.mArticleInfo.aa != null) {
            com.ss.android.article.base.feature.detail.model.ArticleInfo.a v1 = this.mArticleInfo.aa;
            if ((v1.mBannerAdsData == null || !v1.mBannerAdsData.isValid())
                    && (v1.a == null || !v1.a.isValid())
                    && (v1.d == null || !v1.d.isValid())
                    && (v1.b == null || !v1.b.isValid())
                    && (v1.g == null || !v1.g.isValid())
                    && (v1.f == null || !v1.f.isValid() || (ToolUtils.isAppInstalled(this.mActivity, v1.f.pkg)))) {
                if (v1.e == null) {
                    return v0;
                }

                if (!v1.e.isValid()) {
                    return v0;
                }
            }

            v0 = true;
        }

        return v0;
    }

    private static LinearLayout.LayoutParams b(int topMargin) {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        layoutParams.topMargin = topMargin;
        return layoutParams;
    }

    public final void c() {
        if (this.mArticleInfo != null && this.mArticleInfo.aa != null) {
            if (this.mArticleInfo.mDownloadAppAd != null && (this.mArticleInfo.mDownloadAppAd.isValid()) && this.mAppAdViewHolder != null) {
                this.mAppAdViewHolder.b();
            }

            if (this.mDetailAdVideoLayout != null) {
                DetailAdVideoLayout detailAdVideoLayout = this.mDetailAdVideoLayout;
                if (detailAdVideoLayout.c != null) {
                    detailAdVideoLayout.c.d();
                }
            }

            if (this.mDetailAdLargePicLayout != null) {
                this.mDetailAdLargePicLayout.b();
            }

            if (this.mDetailAdSmallPicLayout != null) {
                this.mDetailAdSmallPicLayout.b();
            }

            if (this.mDetailAdGroupPicLayout == null) {
                return;
            }

            this.mDetailAdGroupPicLayout.b();
        }
    }

    public final void d() {
        int v7 = R.color.yo;
        Drawable v6 = null;
        boolean v4 = AppData.isNightMode();
        if (this.n != null) {
            this.n.setTextColor(this.mActivity.getResources().getColor(com.ss.android.article.browser.R.color.ssxinzi2));
        }

        if (this.mTagLayout != null) {
            this.mTagLayout.a();
        }

        if (this.mLikeAndRewardsLayout != null) {
            LikeAndRewardsLayout v5 = this.mLikeAndRewardsLayout;
            v5.d.setBackgroundColor(v5.getResources().getColor(com.ss.android.article.browser.R.color.ssxinxian1));
            v5.a.setTextColor(v5.getResources().getColorStateList(com.ss.android.article.browser.R.color.bu));
            v5.a.setCompoundDrawablesWithIntrinsicBounds(v5.getResources().getDrawable(com.ss.android.article.browser.R.drawable.o8), v6, v6, v6);
            v5.mDiggLayout.adaptNightMode(v4);
            v5.b.setTextColor(v5.getResources().getColorStateList(v7));
            v5.g.setTextColor(v5.getResources().getColor(v7));
            int v6_1 = v5.f.getChildCount();
            if (v6_1 > 0) {
                int v3;
                for (v3 = 0; v3 < v6_1; ++v3) {
                    View v7_1 = v5.f.getChildAt(v3);
                    View v0 = v7_1.findViewById(com.ss.android.article.browser.R.id.avatar);
                    if (v0 != null) {
                        RoundingParams roundingParams = ((GenericDraweeHierarchy) ((NightModeAsyncImageView) v0).getHierarchy()).mRoundingParams;
                        roundingParams.setBorder(v5.getResources().getColor(com.ss.android.article.browser.R.color.b1), TypedValue.applyDimension(1, 0.5f, v5.getResources().getDisplayMetrics()));
                        ((GenericDraweeHierarchy) ((NightModeAsyncImageView) v0).getHierarchy()).setRoundingParams(roundingParams);
                        ((NightModeAsyncImageView) v0).adaptNightMode(v4);
                    }

                    v0 = v7_1.findViewById(com.ss.android.article.browser.R.id.mark_v);
                    if (v0 != null) {
                        ((ImageView) v0).setImageResource(com.ss.android.article.browser.R.drawable.icon_vip);
                    }
                }
            }
        }

        if (this.d != null) {
            RelatedNewsLayout v3_1 = this.d;
            AppData.getInstance();
            AppData.isNightMode();
            v3_1.setBackgroundResource(com.ss.android.article.browser.R.drawable.h6);
            int childCount = v3_1.getChildCount();
            for (int i = 0; i < childCount; ++i) {
                ((RelatedNewsHolder) v3_1.getChildAt(i).getTag()).a();
            }
        }

        if (this.mDetailAdAppLayout != null) {
            this.mDetailAdAppLayout.adaptNightMode(v4);
        }

        if (this.mAppAdViewHolder != null) {
            this.mAppAdViewHolder.a();
        }

        if (this.mDetailAdMixBannerLayout != null) {
            this.mDetailAdMixBannerLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdVideoLayout != null) {
            this.mDetailAdVideoLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdSmallPicLayout != null) {
            this.mDetailAdSmallPicLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdLargePicLayout != null) {
            this.mDetailAdLargePicLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdImageLayout != null) {
            this.mDetailAdImageLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdBannerLayout != null) {
            this.mDetailAdBannerLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdTextLinkLayout != null) {
            this.mDetailAdTextLinkLayout.adaptNightMode();
        }

        if (this.mDetailAdMediaLayout != null) {
            this.mDetailAdMediaLayout.adaptNightMode(v4);
        }

        if (this.mDetailAdGroupPicLayout != null) {
            this.mDetailAdGroupPicLayout.adaptNightMode(v4);
        }
    }

    public final void e() {
        if (this.mDetailAdVideoLayout != null && this.mDetailAdContainer != null) {
            this.mDetailAdVideoLayout.releaseMedia();
        }
    }
}

